using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
using System.Data;
using System.Web;
using System.Xml;
using System.Xml.XPath;

using Actions;
using Actions.Databases;
using Actions.Connectors;
using Actions.Security;
using Actions.Usecases;

namespace Actions.MetaBase
{
	public class MetaBaseModel
	{
		private string _databaseId = "";					
		private string _regExpId = "^[0-9]{1,32}$";		
		private string _regExpName = "^[0-9a-zA-Z_]{4,32}$";		
		
		public string regId 
		{
			get {
				return _regExpId;
			}
		} 
				
		public MetaBaseModel()
		{
			_databaseId = Manager.i.config.GetValueOf("//Configuration/MetaBase/DatabaseID");		
		}
		
		public string showCollections()
		{
			string s = "<metabase>";
			
			s += Manager.i.db(_databaseId).
				query("SELECT * FROM _collections ORDER BY title").
				serializeAsList("collections", "item");
			s += Manager.i.dbp.info;		
						
			return s + "</metabase>";
		}
		
		public string showCollection(string id)
		{
			string s = "<metabase>";
		
			Collection c = new Collection(_databaseId, id);		
			s += c.show();
			s += Manager.i.dbp.info;		
						
			return s + "</metabase>";
		}
	}
}